<template>
  <div class="app">
    <!-- 头部 -->
    <van-nav-bar
      :title="title"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />
    <!-- 中间切换区域 -->
    <router-view></router-view>
    <!-- footer -->
    <van-tabbar v-model="active">
      <van-tabbar-item
        icon="home-o"
        to="/home"
      ></van-tabbar-item>
      <van-tabbar-item
        icon="friends-o"
        to="/friends"
      ></van-tabbar-item>
      <van-tabbar-item
        icon="cart-o"
        to="/cart"
        badge="6"
      ></van-tabbar-item>
      <van-tabbar-item
        icon="search"
        to="/search"
      ></van-tabbar-item>
    </van-tabbar>
  </div>
</template>
<script>
export default {
  data: () => ({
    title: sessionStorage.title || 'home',
    active: Number(sessionStorage.active) || 0
  }),
  methods: {
    onClickLeft() {
      // 返回上一页
      this.$router.go(-1)
    }
  },
  watch: {
    '$route.meta'(meta) {
      this.title = meta.title
      this.active = meta.active
      sessionStorage.title = meta.title
      sessionStorage.active = meta.active
    }
  }
}
</script>
<style lang="less" scoped>
.app {
  // .title {
  //   color: red;
  // }
}
</style>
